<?php

namespace app\common\model;

use think\Model;

// 好友表
class Friend extends Model
{
    protected $name = 'friend';

    protected $autoWriteTimestamp = true;

    protected $createTime = 'createtime';
    protected $updateTime = false;

    protected $append = [
        'createtime_text',
    ];

    public function getCreatetimeTextAttr($value, $data)
    {
        $createtime = isset($data['createtime']) ? $data['createtime'] : '';

        if (empty($createtime)) {
            return '';
        }

        return date('Y-m-d H:m:s', $createtime);
    }

    public function focus()
    {
        return $this->belongsTo('app\common\model\Business\Business', 'fansid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function fans()
    {
        return $this->belongsTo('app\common\model\Business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
